package com.yjm.tb.widget;

import java.io.IOException;

import com.yjm.tb.R;
import com.yjm.tb.model.TbConfig;

import android.content.Context;
import android.media.MediaPlayer;
import android.util.Log;

public class TbMediaPlayer {
	private MediaPlayer mp;
	
	public TbMediaPlayer(Context ctx) {
		mp = MediaPlayer.create(ctx, R.raw.wheel); 
	}

	public void start() {
		try {
			TbConfig config = TbConfig.getInstance();
			if (config.isEnableAudio()) {
				if (mp != null) {
					mp.stop();
				}
				mp.prepare();
				mp.seekTo(0);
				mp.setLooping(true);
				mp.start();
				Log.i("test", "start media player");
			}
		} catch (IllegalStateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}  
	}
	
	public void stop() {
		TbConfig config = TbConfig.getInstance();
		if (config.isEnableAudio()) {
			mp.stop();
		}
	}
}
